package cn.bingo.yunsj.utils;

import cn.bingo.yunsj.ascept.LogAdvice;
import cn.bingo.yunsj.common.exception.EmException;
import cn.bingo.yunsj.common.exception.OwnException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;

/**
 * 判断文件夹是否存在，不存在自动创建
 */
public class IsDirectory {

    private static final Logger logger = LoggerFactory.getLogger(IsDirectory.class);

    public static void  isDirectory(String path){
        File file = new File(path);
        if(file.isDirectory()) {
            if (!file.exists()) {
                logger.info("文件夹不存在");
                file.mkdirs();
                logger.info("文件夹创建成功!");
            }
        }else{
            if(!file.exists()){
                logger.info("文件不存在");
                try {
                    file.createNewFile();
                    logger.info("文件创建成功");
                } catch (IOException e) {
                    logger.info("文件创建失败");
                    throw new OwnException(EmException.SYSTEM_EXCPTION,e.getMessage());
                }
            }
        }
    }
}
